// pages/account-management/account-management.js

import {Wallet} from "../wallet/wallet.js"
import imgUrl from "../wallet/imgUtil.js"
let app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
       isRealName:false,
       toastTxt:"",
       state:1,
       balanceIcon:imgUrl.balance_icon,
       cardIcon:imgUrl.cardIcon,
       detailIcon:imgUrl.detailIcon,
       rightIcon:imgUrl.rightIcon,
       account:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow () {
    
    Wallet._isRealName(realNameState=>{
      // 0.未认证 1.审核中 2.审核失败 3.已认证
       this.setData({
        state:realNameState
       })
      
      if(realNameState == 0 ){
          this.setData({
             toastTxt:"请先实名认证",
             isRealName:true
          })
      }
      if(realNameState == 1 ){
        this.setData({
           toastTxt:"审核中...",
           isRealName:true
        })
      }

      if(realNameState == 2 ){
        this.setData({
          toastTxt:"审核失败,请重新上传认证",
          isRealName:true
       })
      }

     
      new Wallet(res=>{
        console.log(res.data.balance)
        this.setData({
          account:res.data.balance,
         
        })
      },1)
      
      console.log(realNameState)
    })    
  },
  jumpRecord(){
    wx.navigateTo({
      url: '../withdrawalRecord/withdrawalRecord',
    })
  },
  jumpBankCard(){
    wx.navigateTo({
      url: '../bindBankCard/bindBankCard',
    })
  },
  toWithdral(){
      wx.navigateTo({
        url: '../withdrawal/withdrawal',
      })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  success(res){

  },
  businessSuccess(res){},
  jumpRealName(){
    wx.navigateTo({
      url: '../realName/realName',
    })
  },
  cancelModel(){
    this.setData({
      isRealName:false
    })
    wx.navigateBack()
  }
  
})